//
//  ZJVisitorView.m
//  Weibo29
//
//  Created by 曾静 on 16/6/29.
//  Copyright © 2016年 qq. All rights reserved.
//

#import "ZJVisitorView.h"

@interface ZJVisitorView()

//圆圈
@property (nonatomic, strong)UIImageView *cicleImageView;
//遮罩
@property (nonatomic, strong)UIImageView *coverImageView;
//房子
@property (nonatomic, strong)UIImageView *houseImageView;
//登录按钮
@property (nonatomic, strong)UIButton *loginBtn;
//注册按钮
@property (nonatomic, strong)UIButton *registerBtn;
//描述Label
@property (nonatomic, strong)UILabel *desLabel;

@end
@implementation ZJVisitorView

-(UIImageView *)cicleImageView{
    if (!_cicleImageView) {
        _cicleImageView = [[UIImageView alloc]init];
        _cicleImageView.image  =[ UIImage imageNamed:@"visitordiscover_feed_image_smallicon"];
        
    }
    return _cicleImageView;
}

-(UIImageView *)coverImageView{
    if (!_coverImageView) {
        _coverImageView   = [[UIImageView alloc]init];
        _coverImageView.image = [UIImage imageNamed:@"visitordiscover_feed_mask_smallicon"];
    }
    return _coverImageView;
}
-(UIImageView *)houseImageView{
    
    if (!_houseImageView) {
        _houseImageView = [[UIImageView alloc]init];
        _houseImageView.image = [UIImage imageNamed:@"visitordiscover_feed_image_house"];
    }
    return _houseImageView;
    
}

-(UIButton *)loginBtn{
    if (!_loginBtn) {
        _loginBtn = [[UIButton alloc]init];
        [_loginBtn setBackgroundImage:[UIImage imageNamed:@"common_button_white_disable"] forState:UIControlStateNormal];
        
        [_loginBtn setTitle:@"登录" forState:UIControlStateNormal];
        
        [_loginBtn setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
        
        [_loginBtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
        
        [_loginBtn addTarget:self action:@selector(loginBtnClick) forControlEvents:UIControlEventTouchUpInside];

        
        _loginBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        
    }
    return _loginBtn;
}
-(UIButton *)registerBtn{
    if (!_registerBtn) {
        _registerBtn = [[UIButton alloc]init];
        
        
        [_registerBtn setBackgroundImage:[UIImage imageNamed:@"common_button_white_disable"] forState:UIControlStateNormal];
        
        [_registerBtn setTitle:@"注册" forState:UIControlStateNormal];
        
        [_registerBtn setTitleColor:[UIColor orangeColor] forState:UIControlStateHighlighted];
        
        [_registerBtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
        
         [_registerBtn addTarget:self action:@selector(loginBtnClick) forControlEvents:UIControlEventTouchUpInside];
        
        _registerBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    }
    return _registerBtn;
}

-(void)loginBtnClick{
    NSLog(@"点击了登录按钮");
}
-(UILabel *)desLabel{
    if (!_desLabel) {
        _desLabel = [[UILabel alloc]init];
        
        _desLabel.textColor  =[UIColor darkGrayColor];
        
        _desLabel.text = @"关注一些人，回这里看看有什么惊喜关注一些人，回这里看看有什么惊喜";
        
        _desLabel.font =[UIFont systemFontOfSize:14];
        
        _desLabel.numberOfLines = 0;
        
        _desLabel.textAlignment = NSTextAlignmentCenter;
        
        
        
        
        
        
        
    }
    return _desLabel;
}

-(void)startAnimation{
    //trasform.rotation
    CABasicAnimation *ca = [CABasicAnimation animation];
    
    ca.keyPath = @"transform.rotation";
    
    ca.repeatCount = MAXFLOAT;
    
    ca.removedOnCompletion = NO;
    
    ca.toValue = @(M_PI *2);
    
    ca.duration = 10;
    
    [self.cicleImageView.layer addAnimation:ca forKey:nil];
    
    
    
    
    
    
    
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        //设置视图
        
        [self setupUI];
        
        [self setupContrast];
       
    }
    return self;
}
-(void)setupUI{
    
    self.backgroundColor  = [UIColor RGBWithRed:237 andGreen:237 andBlue:237];
    
    
    [self addSubview:self.cicleImageView];
    
    [self addSubview:self.coverImageView];
    
    [self addSubview:self.houseImageView];
    
    [self addSubview:self.loginBtn];
    
    [self addSubview:self.registerBtn];
    
    [self addSubview:self.desLabel];
}

-(void)setupContrast{
    
    [self.cicleImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.center.equalTo(self);
        
        
    }];
    
    [self.coverImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.center.equalTo(self);
        
    }];
    
    
    [self.houseImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.center.equalTo(self);
    }];
    
    [self.desLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.coverImageView.mas_bottom).offset(16);
        
        make.width.equalTo(@224);
        
        make.height.equalTo(@36);
        
        make.centerX.equalTo(self);
        
    }];
    
    [self.loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        
        make.leading.equalTo(self.desLabel);
        
        make.width.equalTo(@100);
        
        make.height.equalTo(@36);
        
        make.top.equalTo(self.desLabel.mas_bottom).offset(16);
    }];
    
    [self.registerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        
        make.trailing.equalTo(self.desLabel);
        
        make.width.equalTo(@100);
        
        make.height.equalTo(@36);
        
        make.top.equalTo(self.desLabel.mas_bottom).offset(16);
        
    }];
    
}
//一般创建约束不放在layoutSubviews里面
//-(void)layoutSubviews{
//    [super layoutSubviews];
//}

//提供一个共外界调用的方法,直接更改visitorView里面的视图的参数
-(void)changeMainPic:(NSString *)imageName andDesTitle:(NSString *)title andIsHome:(BOOL)isHome{
   
    
    //如果是首界面
    if (isHome) {
        
        [self startAnimation];

        
        
    }else{
        
        self.houseImageView.image = [UIImage imageNamed:imageName];
        
        self.desLabel.text = title;
        
        self.coverImageView.hidden = YES;
        
        
        self.cicleImageView.hidden = YES;
    }
    
    
}


@end
